package com.df.springmvc.model.controller;

import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import com.common.bean.DhtmlGridBean;
import com.common.util.Date.DateUtil;
import com.df.springmvc.common.bean.MsgBean;
import com.df.springmvc.common.util.WFUtil;
import com.df.springmvc.common.util.WebUtil;
import com.df.springmvc.model.services.WorkFlowServices;
import com.df.springmvc.supper.SupperController;

@Controller
@RequestMapping("/model/WorkFlow")
/**
 * 本类仅做一些简单数据处理如:
 *格式验证
 *数据封装
 * @author David
 *
 */
public class WorkFlowController extends SupperController{
	String page_model="model/" + this.getClass().getSimpleName().replace("Controller","") + "_";
	@Autowired
	WorkFlowServices services;
	@Autowired
	MessageSource messageSource;
	
	public WorkFlowController(){
		// TODO Auto-generated constructor stub
	}
	@RequestMapping(value={"/"})
	public String excute(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		try{
			services.view("");
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return page_model;
	}
	@RequestMapping(value={"/query"})
	public void query(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		try{
			DhtmlGridBean gridBean=services.query(getParam_PagingBean(request),getParamMap(request,"map"));
			WebUtil.json(response,new MsgBean(gridBean));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	@RequestMapping(value={"/" + toView})
	public String toView(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		try{
			addRequestAttribute("map",services.view(getParamMap(request,"map").get("guid")));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return page_model + View;
	}
	@Override
	@RequestMapping("/toAdd")
	public String toAdd(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		try{
			WFUtil.load(request);
			HashMap<String,String> map=getParamMap(request);
			map.put("ApplyId","");
			map.put("rootCause","");
			map.put("applytype","");
			map.put("applyer","" + getCurrentUserBean().getUserId());
			map.put("startTime",DateUtil.getInstance().toString());
			map.put("endTime",DateUtil.getInstance().toString());
			map.put("applyStatus","");
			map.put("days","0");
			addRequestAttribute("map",map);
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return page_model + Add;
	}
	@RequestMapping(value={"/" + toUpd})
	public String toUpd(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		try{
			WFUtil.load(request);
			addRequestAttribute("map",services.view(getParamMap(request,"map").get("guid")));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return page_model + Upd;
	}
	@RequestMapping("/toUpd_apply1")
	public String toUpd_apply1(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		// TODO Auto-generated method stub
		try{
			WFUtil.load(request);
			addRequestAttribute("map",services.view(getParamMap(request,"map").get("guid")));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return page_model + "Upd_apply1";
	}
	@RequestMapping("/toUpd_apply2")
	public String toUpd_apply2(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		// TODO Auto-generated method stub
		try{
			WFUtil.load(request);
			addRequestAttribute("map",services.view(getParamMap(request,"map").get("guid")));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return page_model + "Upd_apply2";
	}
	@RequestMapping("/toUpd_apply3")
	public String toUpd_apply3(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		// TODO Auto-generated method stub
		try{
			WFUtil.load(request);
			addRequestAttribute("map",services.view(getParamMap(request,"map").get("guid")));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return page_model + "Upd_apply3";
	}
	@RequestMapping("/toUpd_Personnel")
	public String toUpd_Personnel(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		// TODO Auto-generated method stub
		try{
			WFUtil.load(request);
			addRequestAttribute("map",services.view(getParamMap(request,"map").get("guid")));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return page_model + "Upd_Personnel";
	}
	@RequestMapping("/toUpd_Financial")
	public String toUpd_Financial(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		// TODO Auto-generated method stub
		try{
			WFUtil.load(request);
			addRequestAttribute("map",services.view(getParamMap(request,"map").get("guid")));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return page_model + "Upd_Financial";
	}
	@RequestMapping("/toUpd_Archive")
	public String toUpd_Archive(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		// TODO Auto-generated method stub
		try{
			WFUtil.load(request);
			addRequestAttribute("map",services.view(getParamMap(request,"map").get("guid")));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return page_model + "Upd_Archive";
	}
	@RequestMapping(value={"/" + toDel})
	public String toDel(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		return page_model + Del;
	}
	@RequestMapping(value={"/" + "toTree"})
	public String toTree(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		return page_model + "Tree";
	}
	@RequestMapping(value={"/" + "toChildTable"})
	public String toChildTable(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		return page_model + "ChildTable";
	}
	@RequestMapping(value={"/" + "toChildTableTree"})
	public String toChildTableTree(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		return page_model + "ChildTableTree";
	}
	@RequestMapping(value={"/" + "toAddChildTable"})
	public String toAddChildTable(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		return page_model + "AddChildTable";
	}
	@RequestMapping(value={"/" + "toViewChildTable"})
	public String toViewChildTable(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		return page_model + "ViewChildTable";
	}
	@RequestMapping(value={"/" + doAdd})
	public void doAdd(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		try{
			services.add(getParamMap(request,"map"));
			WebUtil.json(response,new MsgBean("OK"));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
			WebUtil.json(response,new MsgBean(e.getMessage(),false));
		}
	}
	@RequestMapping(value={"/" + doUpd})
	public void doUpd(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		try{
			Object rs=services.upd(getParamMap(request,"map"));
			WebUtil.json(response,new MsgBean(rs));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
			WebUtil.json(response,new MsgBean(e.getMessage(),false));
		}
	}
	@RequestMapping(value={"/" + doDel})
	public void doDel(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		try{
			Object rs=services.del(getParamMap(request,"map"));
			WebUtil.json(response,new MsgBean(rs));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
			WebUtil.json(response,new MsgBean(e.getMessage(),false));
		}
	}
	@Override
	public void doView(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		try{
			Object rs=services.view(getParamMap(request,"map").get("guid"));
			WebUtil.json(response,new MsgBean("OK"));
		}catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
			WebUtil.json(response,new MsgBean(e.getMessage(),false));
		}
	}
	@RequestMapping("/doSubmit")
	public void doSubmit(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		// TODO Auto-generated method stub
		try{
			HashMap<String,String> paramMap=getParamMap(request,"map");
			Object rs=services.doSubmit(paramMap);
			WebUtil.json(response,new MsgBean(rs,true));
		}catch(Exception e){
			// TODO: handle exception
			e.printStackTrace();
			WebUtil.json(response,new MsgBean(e.getMessage(),false));
		}finally{
		}
	}
	@RequestMapping("/doApply1")
	public void doApply1(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		// TODO Auto-generated method stub
		try{
			HashMap<String,String> paramMap=getParamMap(request,"map");
			Object rs=services.doApply1(paramMap);
			WebUtil.json(response,new MsgBean(rs,true));
		}catch(Exception e){
			// TODO: handle exception
			e.printStackTrace();
			WebUtil.json(response,new MsgBean(e.getMessage(),false));
		}finally{
		}
	}
	@RequestMapping("/doApply2")
	public void doApply2(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		// TODO Auto-generated method stub
		try{
			HashMap<String,String> paramMap=getParamMap(request,"map");
			Object rs=services.doApply2(paramMap);
			WebUtil.json(response,new MsgBean(rs,true));
		}catch(Exception e){
			// TODO: handle exception
			e.printStackTrace();
			WebUtil.json(response,new MsgBean(e.getMessage(),false));
		}finally{
		}
	}
	@RequestMapping("/doApply3")
	public void doApply3(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		// TODO Auto-generated method stub
		try{
			HashMap<String,String> paramMap=getParamMap(request,"map");
			Object rs=services.doApply3(paramMap);
			WebUtil.json(response,new MsgBean(rs,true));
		}catch(Exception e){
			// TODO: handle exception
			e.printStackTrace();
			WebUtil.json(response,new MsgBean(e.getMessage(),false));
		}finally{
		}
	}
	@RequestMapping("/doPersonnel")
	public void doPersonnel(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		// TODO Auto-generated method stub
		try{
			HashMap<String,String> paramMap=getParamMap(request,"map");
			Object rs=services.doPersonnel(paramMap);
			WebUtil.json(response,new MsgBean(rs,true));
		}catch(Exception e){
			// TODO: handle exception
			e.printStackTrace();
			WebUtil.json(response,new MsgBean(e.getMessage(),false));
		}finally{
		}
	}
	@RequestMapping("/doFinancial")
	public void doFinancial(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		// TODO Auto-generated method stub
		try{
			HashMap<String,String> paramMap=getParamMap(request,"map");
			Object rs=services.doFinancial(paramMap);
			WebUtil.json(response,new MsgBean(rs,true));
		}catch(Exception e){
			// TODO: handle exception
			e.printStackTrace();
			WebUtil.json(response,new MsgBean(e.getMessage(),false));
		}finally{
		}
	}
	@RequestMapping("/doArchive")
	public void doArchive(ModelMap model,HttpServletRequest request,HttpServletResponse response){
		// TODO Auto-generated method stub
		try{
			HashMap<String,String> paramMap=getParamMap(request,"map");
			Object rs=services.doArchive(paramMap);
			WebUtil.json(response,new MsgBean(rs,true));
		}catch(Exception e){
			// TODO: handle exception
			e.printStackTrace();
			WebUtil.json(response,new MsgBean(e.getMessage(),false));
		}finally{
		}
	}
}
